package com.o2opuzi.pub.dao

import org.springframework.stereotype.Repository;

import com.o2opuzi.lib.db.SupportDao;
import com.o2opuzi.pub.model.Menu;

@Repository
class MenuDao extends SupportDao<Menu>{
	
	/**
	 * 获取子菜单
	 */
	 def List subMenuList(List all,menu){
		def sub_all = [];
		all.each {
			if(it["parent_id"] == menu["id"]){
				def subMap = [:];
				subMap.putAll(it);
				subMap["sub"] =  subMenuList(all,it);
				sub_all.add(subMap);
			}
		}
		return sub_all;
	}

	/**
	 * 获取菜单
	 * @auther Y.hj
	 * @return
	 */
	def getMenuTreeList(){
		def menu_all =  findListForMap(new Menu().ob("sort_num", "asc"));
		def rootTreeMenu = [];
		menu_all.each{
			if(it["parent_id"] == 0){
				def map = [:];
				map.putAll(it);
				map["sub"] = subMenuList(menu_all, it);
				rootTreeMenu.add(map);
			}	
		};
		return rootTreeMenu;
	}
	
}
